//
//  DiagnosisVibrationViewController.m
//  MobileChecker
//
//  Created by Lymons on 15-1-7.
//  Copyright (c) 2015年 Lymons. All rights reserved.
//

#import "DiagnosisVibrationViewController.h"
#import "SelfDiagnosisViewModel.h"
#import "UIDevice+IdentifierAddition.h"

@interface DiagnosisVibrationViewController ()

@property (strong, nonatomic) IBOutlet UIButton *resultOkButton;
@property (strong, nonatomic) IBOutlet UIButton *resultNgButton;
@property (strong, nonatomic) IBOutlet UIButton *resultNoSupportButton;

@property (strong, nonatomic) DiagnosisVibrationViewModel *viewModel;

@end

@implementation DiagnosisVibrationViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self bindViewModel];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    [self.viewModel executeTheCheckCommand:nil];
}

- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:animated];
    [self.viewModel completeTheCheckCommand];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark -

- (void)bindViewModel {
    self.viewModel = [[DiagnosisVibrationViewModel alloc] init];
    void (^resultBlock)(BOOL) = ^(BOOL result) {
        NSLog(@"Vibration is OK : %@", result ? @"YES" : @"NO");
        [self performSegueWithIdentifier:@"VibrationSegueIndentifier" sender:self];
    };
    self.resultOkButton.rac_command = [self.viewModel makeCommandWithBlock:resultBlock simple:YES];
    self.resultNgButton.rac_command = [self.viewModel makeCommandWithBlock:resultBlock simple:NO];
    self.resultNoSupportButton.rac_command = [self.viewModel makeCommandWithBlock:resultBlock detail:DiagnosisCheckResultNoSupport];
    
    RAC(self, resultNgButton.hidden) = [RACObserve([UIDevice currentDevice], hasVibration) not];
    RAC(self, resultOkButton.hidden) = RACObserve(self, resultNgButton.hidden);
    RAC(self, resultNoSupportButton.hidden) = [RACObserve(self, resultNgButton.hidden) not];
}

@end
